<%@ page import="cn.kgc.javaweb.entiy.User" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.HashMap" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>EL表达式处理复杂类型的值</title>
</head>
<body>


<%
    // 简单类型的值  String
    request.setAttribute("str", "stringValue");

    //  对象类型 User
    //User user = new User();
    //user.setAge(20);
    //user.setUsername("Tom");

    User user = new User("jack", 30);
    request.setAttribute("user", user);

    //  数组类型
    int[]  numbers = new int[]{1,2,3,4,5};
    request.setAttribute("array", numbers);

    // 集合类型 List<String>     List<User>
    ArrayList<String> list = new ArrayList<>();
    list.add("aa");
    list.add("bb");
    list.add("cc");
    list.add("dd");
    request.setAttribute("list", list);

    ArrayList<User> users = new ArrayList<>();
    users.add(user);
    users.add(user);
    users.add(user);
    users.add(user);

    request.setAttribute("users", users);

    // Map
    HashMap<String, Object> map = new HashMap<>();
    map.put("username", "admin");
    map.put("password", "123456");
    request.setAttribute("map", map);

%>

<p>----------------简单数据类型----------------------</p>
<p>str = ${str}</p>

<p>----------------User对象数据类型----------------------</p>
<p>str = ${user}</p>
<ul>
<%--
 User   ->  getUsername()   getUname()
    user.uname   uname 代表的并不是user类中的属性   在获取值时 找的时当前key对应的get方法  user.uname    getUname
 --%>
    <li>${user.username}</li>
    <li>${user.age}</li>
</ul>


<p>----------------数组类型的值----------------------</p>
<p>array=${array}</p>

<ul>
    <li>${array[0]}</li>
    <li>${array[1]}</li>
    <li>${array[2]}</li>
    <li>${array[3]}</li>
    <li>${array[4]}</li>
</ul>

<p>----------------list集合类型的值----------------------</p>
<p>array=${list}</p>

<ul>
    <li>${list.get(0)}</li>
    <li>${list.get(1)}</li>
    <li>${list.get(2)}</li>
    <li>${list.get(3)}</li>
</ul>


<p>users=${users}</p>
<p>user = ${users.get(0).username}</p>
<p>user = ${users.get(0).age}</p>

<p>user = ${users.get(1).username}</p>
<p>user = ${users.get(1).age}</p>

<p>user = ${users.get(2).username}</p>
<p>user = ${users.get(2).age}</p>


<p>----------------map集合类型的值----------------------</p>
<p>array=${map}</p>

<ul>
    <li>${map.get("username")}</li>
    <li>${map.get("password")}</li>
</ul>

</body>
</html>
